package ${packageName}.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
<#if swagger>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
</#if>
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.math.BigDecimal;

/**
 * ${classInfo.classComment}
 *
 * @author ${authorName}
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName(value = "${classInfo.tableName}")
<#if swagger>
@ApiModel(value = "${classInfo.className}", description = "${classInfo.classComment}")
</#if>
public class ${classInfo.className} implements Serializable {

    private static final long serialVersionUID = ${classInfo.serialVersionUID}L;

<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
    <#list classInfo.fieldList as fieldItem >
    /**
     * ${fieldItem.fieldComment}
     */
<#if classInfo.pkField == fieldItem.fieldName>
    <#if fieldItem.isAuto>
    @TableId(type = IdType.AUTO)
    <#else>
    <#if fieldItem.fieldClass == "Long">
    @TableId(type = IdType.ASSIGN_ID)
    <#else>
    @TableId
    </#if>
    </#if>
</#if>
<#if fieldItem.fieldClass == "Long">
    @JsonSerialize(using = ToStringSerializer.class)
</#if>
<#if fieldItem.fieldLength gt 0 && fieldItem.fieldName != "isDeleted" && fieldItem.fieldName != "createBy" && fieldItem.fieldName != "updateBy">
    <#if fieldItem.fieldClass == "String">
    @Size(max = ${fieldItem.fieldLength}, message = "length more than ${fieldItem.fieldLength}")
    <#elseif fieldItem.fieldClass == "BigDecimal">
    @DecimalMin(value = "0", message = "greater than zero")
    @DecimalMax(value = "${fieldItem.fieldLength}", inclusive = false , message = "less than ${fieldItem.fieldLength}")
    <#else>
    @Range(min = 0, max = ${fieldItem.fieldLength}, message = "between 0 and ${fieldItem.fieldLength}")
    </#if>
</#if>
<#if fieldItem.isNotNull && fieldItem.fieldName != "createTime" && fieldItem.fieldName != "createBy" && fieldItem.fieldName != "isDeleted" && fieldItem_index != 0>
    <#if fieldItem.fieldClass == "String">
    @NotBlank(message = "not null")
    <#else>
    @NotNull(message = "not null")
    </#if>
    <#if swagger>
    <#if fieldItem.fieldClass == "Long">
    @ApiModelProperty(value = "${fieldItem.fieldComment}", required = true, dataType = "java.lang.String")
    <#else>
    @ApiModelProperty(value = "${fieldItem.fieldComment}", required = true)
     </#if>
    </#if>
<#else>
    <#if swagger>
    <#if fieldItem.fieldClass == "Long">
    @ApiModelProperty(value = "${fieldItem.fieldComment}", dataType = "java.lang.String")
    <#else>
    @ApiModelProperty(value = "${fieldItem.fieldComment}")
    </#if>
    </#if>
</#if>
<#if fieldItem.fieldName == "createTime" || fieldItem.fieldName == "createBy">
    @TableField(fill = FieldFill.INSERT)
</#if>
<#if fieldItem.fieldName == "updateTime"|| fieldItem.fieldName == "updateBy">
    @TableField(fill = FieldFill.UPDATE)
</#if>
<#if fieldItem.fieldName == "createTime">
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
</#if>
<#if fieldItem.fieldName == "updateTime">
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
</#if>
<#if fieldItem.fieldName == "isDeleted">
    @TableLogic
</#if>
    private ${fieldItem.fieldClass} ${fieldItem.fieldName};

    </#list>
</#if>

}
